package n1308;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	static HashMap<Integer, Integer> map=new HashMap<Integer, Integer>();
	
	static boolean solve()
	{
		if(map.isEmpty())return true;
		boolean flag=true;
		for(Iterator<Integer> it=map.keySet().iterator();it.hasNext();)
		{
			Integer key=it.next();
			Integer value=map.get(key);
			if(value==null)
			{
				if(flag==false)return false;
				flag=false;
			}
		}
		if(flag==false)return true;
		return false;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		Scanner cin=new Scanner(bf);
		int t=0;
		boolean flag=true;
		while(true)
		{
			int n1=cin.nextInt();
			int n2=cin.nextInt();
			if(n1<0&&n2<0)break;
			if(n1==0&&n2==0) {
				//print
				t++;
				if(flag&&solve()) {
					System.out.println("Case "+t+" is a tree.");
				}else {
					System.out.println("Case "+t+" is not a tree.");
				}
				map.clear();
				flag=true;
			}else {
				if((map.containsKey(n2)&&map.get(n2)!=null))
				{
					flag=false;
				}
				else if(map.containsKey(n1)&&map.get(n1)!=null&&map.get(n1).equals(n2)){
					flag=false;
				}
				else {
					if(!map.containsKey(n1))map.put(n1, null);
					map.put(n2, n1);
				}
			}
		}
	}

}
